package fr.idak.spring.tiles.dao.impl;

import static org.hibernate.criterion.Restrictions.eq;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import fr.idak.spring.tiles.dao.LanguageDao;
import fr.idak.spring.tiles.hibernate.entity.Language;
import fr.idak.sring.tiles.generic.dao.GenericDaoHibernateImpl;

@Repository
public class LanguageDaoImpl extends GenericDaoHibernateImpl<Language, Integer> implements LanguageDao {
	
	@SuppressWarnings("unchecked")
	public List<Language> getLanguageByReleaseDate(String releaseDate) {
		Session session = sessionFactory.getCurrentSession();
		Criteria criteria = session.createCriteria(entityClass);
		criteria.add(eq("beginDt", releaseDate));
		return (List<Language>) criteria.list();
	}

	public List<Language> getLanguagesByIndex(int begin, int end) {
		Session session = sessionFactory.getCurrentSession();
		Criteria criteria = session.createCriteria(entityClass);
		criteria.setFirstResult(begin);
		criteria.setMaxResults(end);
		return (List<Language>) criteria.list();
	}
}
